package com.yixun.qfbao.response.premises;

import com.yixun.qfbao.apidto.PremisesArea;
import com.yixun.qfbao.apidto.base.CommonResDTO;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author guifang.weng
 * @create 2017-12-01 14:02
 **/
public class GetPremisesAreaAndCityListResDto extends CommonResDTO implements Serializable {
    private static final long serialVersionUID = -5847692178705321054L;

    private List<PremisesArea> premisesCityList;

	public List<PremisesArea> getPremisesCityList() {
		return premisesCityList;
	}

	public void setPremisesCityList(List<PremisesArea> premisesCityList) {
		this.premisesCityList = premisesCityList;
	}

    public GetPremisesAreaAndCityListResDto() {
    }
    
    public GetPremisesAreaAndCityListResDto(List<PremisesArea> premisesList) {
    	// 遍历获取所有的地市信息
    	for (PremisesArea premisesCity : premisesList) {
			if(premisesCity.getAreaFlag() == 0) {
				if(this.premisesCityList == null) {
					premisesCityList = new ArrayList<>();
				}
				premisesCityList.add(premisesCity);
				Long areaId = premisesCity.getAreaId();
				List<PremisesArea> premisesAreaList = new ArrayList<>();
				
				// 把遍历获取到的区县信息放到对应的地市下
				for (PremisesArea premisesArea : premisesList) {
					if(premisesArea.getAreaFlag() == 1 && premisesArea.getParentId().longValue() == areaId) {
						premisesAreaList.add(premisesArea);
					}
				}
				premisesCity.setPremisesAreaList(premisesAreaList);
			}
		}
    }
}
